import React, { useEffect } from "react";
import Router from "./router";
import { useLocation, useNavigate } from "react-router-dom";

const App = () => <Router></Router>;

const withLogin = (Comp) => {
  return () => {
    const { pathname } = useLocation();
    const navigate = useNavigate();
    const whiteList = ["/login", "/register"];
    useEffect(() => {
      if (!whiteList.includes(pathname) && !localStorage.getItem("userInfo")) {
        navigate("/login");
      }
    }, [pathname]);
    return <Comp></Comp>;
  };
};

export default withLogin(App);
